package com.gph.saviorframework.wf.service.impl;

import com.gph.saviorframework.wf.service.ActivitiHisService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by root on 16-8-8.
 */
public class ActivitiHisServiceImpl implements ActivitiHisService {

    @Autowired
    private HistoryService historyService;

    /**
     * 根据流程编号和pvmActivityId获取历史activity信息
     *
     * @param processInsId
     * @param pvmActivityId
     * @return
     */
    public HistoricActivityInstance findHistoricActivityInstanceByInsIdAndActivitiId(String processInsId, String pvmActivityId) {

        List<HistoricActivityInstance> list =  historyService.createHistoricActivityInstanceQuery()
                .processInstanceId(processInsId)
                .activityId(pvmActivityId)
                .orderByHistoricActivityInstanceStartTime()
                .desc().list();
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
